package com.lianxi.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletResponse;

@Component
public class CommonResult<T> {
    private int code;
    private String message;
    private T data;

    public CommonResult(int code,String message){
        this.code=code;
        this.message=message;
    }


    //成功返回查询的数据
    public static <E> CommonResult<E> success(E data) {
        return new CommonResult<E>(200,"success",data);
    }

    //成功不返回结果
    public static  CommonResult successNoData(){
        return new CommonResult(200,"success");
    }


    //失败。不返回结果
    public static  CommonResult fail(){
        return new CommonResult(444,"fail");
    }
    //失败。不返回结果
    public static  CommonResult error(String message){
        return new CommonResult(444,message);
    }

    //失败
    public static  CommonResult unEnable(){
        return new CommonResult(445,"账户不可用");
    }

    //失败，返回结果
    public static  <E> CommonResult<E> failHaveData(E data){
        return new CommonResult<E>(444,"fail",data);
    }


    //失败，没有查询到相关信息哦~
    public static  CommonResult failNoDatas(){
        return new CommonResult(444,"没有查询到相关信息哦");
    }

    //失败，没有查询到相关信息哦~
    public static  CommonResult failLogin(){
        return new CommonResult(444,"登陆失败啦哦~");
    }


    public CommonResult() {
    }

    public CommonResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
    //失败不返回结果
//    public static CommonResult fail(){
//        return new CommonResult(444,"fail",null);
//    }

    //成功返回结果
//    public  CommonResult success(T data){
//        return new CommonResult(200,"success",data);
//    }


    //成功不返回结果
//    public static CommonResult successNoData(){
//        return new CommonResult(200,"success",null);
//    }


}
